package array;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 快慢指针解移动零
 * 定义两个指针，fast 和 slow
 * 如果fast位置为不为0，把fast对应的值覆盖到slow索引对应的值
 * 如果fast位置为0，则fast++，slow不变
 * 最后将slow索引之后的位置都变为0即可
 *
 * [0,1,0,3,12]
 * [1, 3, 12, 0, 0]
 */
public class MoveZeros {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] split = s.substring(1, s.length() - 1).split(",");

        int[] nums = new int[split.length];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = Integer.parseInt(split[i]);
        }

        //快慢指针移动零
        int slowIndex = 0;
        for (int fastIndex = 0; fastIndex < nums.length; fastIndex++){
            if(nums[fastIndex] != 0){
                nums[slowIndex] = nums[fastIndex];
                slowIndex++;
            }
        }
        for (int i = slowIndex; i < nums.length; i++){
            nums[i] = 0;
        }
        System.out.println(Arrays.toString(nums));

        sc.close();
    }
}
